//
//  DetailViewController.m
//  ipad_split
//
//  Created by user on 12-8-16.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "DetailViewController.h"
#import "ViewController1.h"
#import "ViewController2.h"
#import "ViewController3.h"
#import "YKBrandsCell.h"
#import "YKXIBHelper.h"
#import "YKImage.h"
#import "WEPopoverController.h"

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define DEGREES_TO_RADIANS(d) (d * M_PI / 180)

@implementation UIScrollView_Test


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"BaseTableView : began");
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"BaseTableView : move");
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"BaseTableView : end");
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"BaseTableView : cancel");
}

- (void)setUIGestureRecognizer {
    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
    [self addGestureRecognizer:swipe];
    [swipe release];
}

- (void)swipe:(UISwipeGestureRecognizer *)gestureRecognizer {
    NSLog(@"swipe");
}

- (void)dealloc {
    [super dealloc];
}

@end




@interface DetailViewController ()
@property (strong, nonatomic) UIPopoverController *masterPopoverController;
- (void)configureView;
@end

@implementation DetailViewController
@synthesize txtName = _txtName;

@synthesize uibgimage;
@synthesize uibgimage1;
@synthesize detailItem = _detailItem;
@synthesize detailDescriptionLabel = _detailDescriptionLabel;
@synthesize masterPopoverController = _masterPopoverController;

- (void)dealloc
{
    [_detailItem release];
    [_detailDescriptionLabel release];
    [_masterPopoverController release];
    [_txtName release];
    [uibgimage release];
    [uibgimage1 release];
    [super dealloc];
}

#pragma mark - Managing the detail item

- (void)setDetailItem:(id)newDetailItem
{
    if (_detailItem != newDetailItem) {
        [_detailItem release];
        _detailItem = [newDetailItem retain];

        // Update the view.
        [self configureView];
    }

    if (self.masterPopoverController != nil) {
        [self.masterPopoverController dismissPopoverAnimated:YES];
    }
}

- (void)configureView
{
    // Update the user interface for the detail item.

    if (self.detailItem) {
        self.detailDescriptionLabel.text = [self.detailItem description];
    }
}

#pragma mark -
#pragma mark YKBrandsGridViewDelegate

-(void) gridView:(YKBrandsGridView*) agridView didSelectCell:(YKBrandsGridViewCell*) acell atIndex:(unsigned int) aindex
{
    //    [[agridView viewWithTag:101] viewWithTag:102];
    [self goProductList:nil];
}

-(void) gridView:(YKBrandsGridView*) agridView willSelectCell:(YKBrandsGridViewCell*) acell atIndex:(unsigned int) aindex 
{
}

-(void) gridView:(YKBrandsGridView*) agridView willDisplayCell:(YKBrandsGridViewCell*) acell atIndex:(unsigned int) aindex
{
}

-(void) gridView:(YKBrandsGridView*) agridView didSelectCellOutSizeUp:(YKBrandsGridViewCell*) acell atIndex:(unsigned int) aindex
{
}

-(void) gridView:(YKBrandsGridView*) agridView didSelectCellUp:(YKBrandsGridViewCell*) acell atIndex:(unsigned int) aindex
{
    //    NSArray *array = listService.brandsDataInfo.brandsArray;
    //    if (agridView.tag < 0 || agridView.tag >= [array count]) {
    //        return ;
    //    }
    //    YKBrandsGroupItem *item = [array objectAtIndex:agridView.tag];
    //    YKProductlistViewController *productlist=[[YKProductlistViewController alloc]init];
    //    YKBrandsItem * brandItem = [item.itemList objectAtIndex:aindex];
    //    productlist.queryString = brandItem.Search_condition;
    //    [self.navigationController pushViewController:productlist animated:NO];
    //    [productlist release];
}

#pragma mark -
#pragma mark YKBrandsGridViewDataSource

- (unsigned int) numOfGridViewItem:(YKBrandsGridView*) agridView {
    return 15;
}

- (CGSize) sizeOfGridViewItem:(YKBrandsGridView*) agridView {
    return CGSizeMake(160, 134);//160*134
}

- (void)goProductList:(id)sender
{
    ViewController1 * view1 = [[ViewController1 alloc] initWithNibName:@"ViewController1" bundle:nil];
    view1.pDD = self;
    UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:view1];
    nav.modalPresentationStyle = UIModalPresentationFullScreen;
    nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:nav animated:YES];
    //下面设置presentModalViewController的大小
    nav.view.superview.frame = CGRectMake(0, 0, 1000, 374);
    nav.view.superview.center = self.view.center;
    //这句有时候获取到的并不是正中，我的情况就是，然后用了下面的这个固定坐标
    nav.view.superview.center = CGPointMake(512,374);

}

- (YKBrandsGridViewCell*) gridView:(YKBrandsGridView*) agridView cellForIndex:(unsigned int) aindex{
//    NSArray *array = listService.brandsDataInfo.brandsArray;
//    if (agridView.tag < 0 || agridView.tag >= [array count]) {
//        return nil;
//    }
//    YKBrandsGroupItem *item = [array objectAtIndex:agridView.tag];
    
    static NSString    * identifier = @"cell";
    YKBrandsCell  * cell = (YKBrandsCell*)[agridView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = (YKBrandsCell*)[self loadCell];
        cell.backgroundColor = [UIColor clearColor];
        [cell.optimage setImageFromUrl:@"http://www.lanrentuku.com/down/png/0907/computer-things/computer-things-01.png"];
    }
//    for (UIView *view in cell.subviews) {
//        if ([[view class]isSubclassOfClass:[UIImageView class]]) {
//            [view removeFromSuperview];
//        }
//    }
    
    
//    UIButton * btnBrands = [UIButton buttonWithType:UIButtonTypeCustom];
//    btnBrands.tag = agridView.tag;
//    [btnBrands addTarget:self action:@selector(goProductList:) forControlEvents:UIControlEventTouchUpInside];
//    btnBrands.frame = CGRectMake((160-120)/2, 0, 120, 80);
////    [btnBrands setImage:self.uibgimage.image forState:UIControlStateNormal];
////    [btnBrands setImage:self.uibgimage1.image forState:UIControlStateHighlighted];
//    [cell addSubview:btnBrands];
//    
//    UILabel *lable_name=[[UILabel alloc]initWithFrame:CGRectMake(0, 93, 120, 15)];
//    lable_name.text=@"hello";
//    lable_name.numberOfLines=1;
//    lable_name.lineBreakMode=UILineBreakModeTailTruncation;
//    lable_name.backgroundColor=[UIColor clearColor];
//    lable_name.font=[UIFont systemFontOfSize:12];
//    lable_name.textAlignment = UITextAlignmentCenter;
//    lable_name.textColor = [UIColor redColor];
//    [btnBrands addSubview:lable_name];
//    [lable_name release];
//    
//    UILabel * lable_Search = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
//    lable_Search.tag = 102;
//    lable_Search.text = @"doudou";
//    [lable_Search setHidden:YES];
//    [btnBrands addSubview:lable_Search];
//    [lable_Search release];
    
    return cell;
}

- (YKBrandsGridViewCell*) loadCell{
    YKBrandsCell* ret = (YKBrandsCell*)[YKXIBHelper loadObjectFromXIBName:@"YKBrandsCell" type:[YKBrandsCell class]];
    return ret;
}

- (void)createGridView
{
    gridview = [[YKBrandsGridView alloc] initWithFrame:CGRectMake(0, 0, 500, 600)];
    gridview.scrollEnabled = YES;
    gridview.delegate_grid = self;
    gridview.dataSource = self;
    gridview.backgroundColor = [UIColor clearColor];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    [self configureView];
    
//    [self createGridView];
//    [self.view addSubview:gridview];
//    return;
    UIScrollView_Test *scrollview =[[UIScrollView_Test alloc] initWithFrame:CGRectMake(300, 0, 200, 200)];
    scrollview.backgroundColor=[UIColor redColor];
    scrollview.contentSize=CGSizeMake(400, 200);
    [self.view addSubview:scrollview];
    [scrollview release];
    
    [self.uibgimage setImageFromUrl:@"http://www.lanrentuku.com/down/png/0907/computer-things/computer-things-06.png"];
    [self.uibgimage1 setImageFromUrl:@"http://www.lanrentuku.com/down/png/0907/computer-things/computer-things-01.png"];
//    [self newViewDidLoad];
//    return;
    a = [[ViewController1 alloc] initWithNibName:@"ViewController1" bundle:nil];
    b = [[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:nil];
    c = [[ViewController3 alloc] initWithNibName:@"ViewController3" bundle:nil];
    a.view.frame = CGRectMake(50, 500, 100, 100);
    b.view.frame = CGRectMake(50, 450, 100, 100);
    c.view.frame = CGRectMake(50, 450, 100, 100);
    a.view.hidden = NO;
    b.view.hidden = YES;
    c.view.hidden = YES;
    
    isAShow = true;
    
    [self.view addSubview:a.view];
    [self.view addSubview:b.view];
    [self.view addSubview:c.view];
    
//    [a release];
//    [b release];
//    [c release];
    
    //初始化一个layer,添加到主视图
    layer = [CALayer layer];
    layer.bounds = CGRectMake(0, 0, 200, 200);
    layer.position = CGPointMake(160, 250);
    layer.backgroundColor = [UIColor redColor].CGColor;
    layer.borderColor = [UIColor blackColor].CGColor;
    layer.opacity = 1.0f;
    [self.view.layer addSublayer:layer];
    layer.cornerRadius = (layer.cornerRadius == 0.0f) ? 30.0f : 0.0f;
    
    //提交其他
    anotherLayer = [CALayer layer];
    anotherLayer.bounds = CGRectMake(0, 0, 200, 200);
    anotherLayer.position = CGPointMake(400, 400);
    anotherLayer.backgroundColor = [UIColor grayColor].CGColor;
    anotherLayer.borderColor = [UIColor blackColor].CGColor;
    anotherLayer.opacity = 1.0f;
    [self.view.layer addSublayer:anotherLayer];
    [super viewDidLoad];
}

-(IBAction)moveView:(id)sender
{
//    [CATransaction begin];
//    //显式事务默认开启动画效果,kCFBooleanTrue关闭
//    [CATransaction setValue:(id)kCFBooleanFalse forKey:kCATransactionDisableActions];
//    
//    //动画执行时间
//    [CATransaction setValue:[NSNumber numberWithFloat:0.6f] forKey:kCATransactionAnimationDuration];
//    //[CATransaction setAnimationDuration:[NSNumber numberWithFloat:5.0f]];
//    //    layer.cornerRadius = (layer.cornerRadius == 0.0f) ? 30.0f : 0.0f;
////    a.view.layer.opacity = (a.view.layer.opacity == 1.0f) ? 0.0f : 1.0f;
//    if (a.view.frame.origin.y == 400) {
//        a.view.frame = CGRectMake(50, 500, 100, 100);
//    } else {
//        a.view.frame = CGRectMake(50, 400, 100, 100);
//    }
//    [CATransaction commit];
    
    if (!isAShow) {
        [UIView animateWithDuration:0.5
                         animations:^{b.view.frame = CGRectMake(50, 450, 100, 100);b.view.alpha=0.0;}
                         completion:^(BOOL finished){}];
        isAShow = YES;
    } else {
        [UIView animateWithDuration:0.5
                         animations:^{a.view.frame = CGRectMake(50, 450, 100, 100);a.view.alpha=0.0;}
                         completion:^(BOOL finished){}];
        isAShow = NO;
    }
    [self performSelector:@selector(goOldPostion) withObject:nil afterDelay:0.5f];
    
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}

- (IBAction)coverflow:(id)sender {
    UIButton* btn=(UIButton*)sender;
    ViewController3 * view3 = [[ViewController3 alloc] initWithNibName:@"ViewController3" bundle:nil];
    UINavigationController* navController=[[UINavigationController alloc] initWithRootViewController:view3];
    navController.navigationBar.tintColor=[UIColor redColor];
    WEPopoverController* sizeTablePopoverController=[[WEPopoverController alloc] init]; //initWithContentViewController:navController];
    sizeTablePopoverController.contentViewController=navController;
    sizeTablePopoverController.popoverContentSize=CGSizeMake(600, 300);
    if(UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])){
		[sizeTablePopoverController presentPopoverFromRect:btn.frame inView:btn.superview permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
	}else{
		[sizeTablePopoverController presentPopoverFromRect:btn.frame inView:btn.superview permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
	}
    [navController release];
	[view3 release];
    
    /*
    UIButton* btn=(UIButton*)sender;
    ViewController3 * view3 = [[ViewController3 alloc] initWithNibName:@"ViewController3" bundle:nil];
//    [self.navigationController pushViewController:view3 animated:YES];
    
    UINavigationController* navController=[[UINavigationController alloc] initWithRootViewController:view3];
	UIPopoverController* sizeTablePopoverController=[[UIPopoverController alloc] initWithContentViewController:view3];
    [sizeTablePopoverController setValue:[NSNumber numberWithInt:5] forKey:@"popoverBackgroundStyle"];
	//controller.popoverController=sizeTablePopoverController;
	sizeTablePopoverController.popoverContentSize=CGSizeMake(400, 300);
	if(UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])){
		[sizeTablePopoverController presentPopoverFromRect:btn.frame inView:btn.superview permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
	}else{
		[sizeTablePopoverController presentPopoverFromRect:btn.frame inView:btn.superview permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
	}
//	[popoverControllerArray addObject:sizeTablePopoverController];
	[navController release];
	[view3 release];
     */
}

- (void)goDoSomethingLongAndInvolved
{
    for (int i = 0; i < 1000000000; i++) {
        NSLog(@"data:%d", i);
    }
}

- (IBAction)gcdClick:(id)sender {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self goDoSomethingLongAndInvolved];
        dispatch_async(dispatch_get_main_queue(), ^{
            //[textField setStringValue:@"Done doing something long and involved"];
            [self.txtName setText:@"hellddddddddddo"];
        });
    });
}

- (IBAction)gridviewTouch:(id)sender {
    GridViewController * viewctl = [[GridViewController alloc] initWithNibName:@"GridViewController" bundle:nil];
    [self.navigationController pushViewController:viewctl animated:YES];
    [viewctl release];
}

- (void)goOldPostion
{
    if (!isAShow) {
        [UIView animateWithDuration:0.6
                         animations:^{b.view.frame = CGRectMake(50, 500, 100, 100);b.view.alpha=1.0;
                             b.view.hidden = NO;a.view.hidden = YES;}
                         completion:^(BOOL finished){}];
    } else {
        [UIView animateWithDuration:0.6
                         animations:^{a.view.frame = CGRectMake(50, 500, 100, 100);a.view.alpha=1.0;
                         a.view.hidden = NO;b.view.hidden = YES;}
                         completion:^(BOOL finished){}];
    }
}

- (void)newViewDidLoad
{
//    self.title = [[self class] displayName];
    
    self.view.backgroundColor = [UIColor blackColor];
    
    CGFloat radius = 30.0f;
    CGFloat diameter = radius * 2;
    CGPoint arcCenter = CGPointMake(radius, radius);
    
    // Create a UIBezierPath for Pacman's open state
    pacmanOpenPath = [[UIBezierPath bezierPathWithArcCenter:arcCenter
                                                     radius:radius 
                                                 startAngle:DEGREES_TO_RADIANS(35)
                                                   endAngle:DEGREES_TO_RADIANS(315)
                                                  clockwise:YES] retain];    
    
    
    [pacmanOpenPath addLineToPoint:arcCenter];
    [pacmanOpenPath closePath];
    
    // Create a UIBezierPath for Pacman's close state
    pacmanClosedPath = [[UIBezierPath bezierPathWithArcCenter:arcCenter
                                                       radius:radius 
                                                   startAngle:DEGREES_TO_RADIANS(1)
                                                     endAngle:DEGREES_TO_RADIANS(359)
                                                    clockwise:YES] retain];
    [pacmanClosedPath addLineToPoint:arcCenter];
    [pacmanClosedPath closePath];    
    
    // Create a CAShapeLayer for Pacman, fill with yellow
    shapeLayer = [CAShapeLayer layer];
    shapeLayer.fillColor = [UIColor yellowColor].CGColor;
    shapeLayer.path = pacmanClosedPath.CGPath;
    shapeLayer.strokeColor = [UIColor grayColor].CGColor;
    shapeLayer.lineWidth = 1.0f;
    shapeLayer.bounds = CGRectMake(0, 0, diameter, diameter);
    shapeLayer.position = CGPointMake(-40, -100);
    [self.view.layer addSublayer:shapeLayer];
    
    SEL startSelector = @selector(startAnimation);
    UIGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:startSelector];
    [self.view addGestureRecognizer:recognizer];
    [recognizer release];
    
    // start animation after short delay
    [self performSelector:startSelector withObject:nil afterDelay:1.0];
}

- (void)startAnimation {
    
    // Create CHOMP CHOMP animation
    CABasicAnimation *chompAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
    chompAnimation.duration = 0.25;
    
    chompAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    chompAnimation.repeatCount = HUGE_VALF;
    chompAnimation.autoreverses = YES;
    // Animate between the two path values
    chompAnimation.fromValue = (id)pacmanClosedPath.CGPath;
    chompAnimation.toValue = (id)pacmanOpenPath.CGPath;
    
    [shapeLayer addAnimation:chompAnimation forKey:@"chompAnimation"];
    
    // Create digital '2'-shaped path
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(-40, 100)];
    [path addLineToPoint:CGPointMake(360, 100)];
    [path addLineToPoint:CGPointMake(360, 200)];
    [path addLineToPoint:CGPointMake(-40, 200)];
    [path addLineToPoint:CGPointMake(-40, 300)];
    [path addLineToPoint:CGPointMake(360, 300)];
    
    CAKeyframeAnimation *moveAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    moveAnimation.path = path.CGPath;
    moveAnimation.duration = 8.0f;
    // Setting the rotation mode ensures Pacman's mouth is always forward.  This is a very convenient CA feature.
    moveAnimation.rotationMode = kCAAnimationRotateAuto;
    [shapeLayer addAnimation:moveAnimation forKey:@"moveAnimation"];
} 

-(IBAction)changeLayerProperty
{
    //设置变化动画过程是否显示，默认为YES不显示
    [CATransaction setDisableActions:NO];
    //设置圆角
    layer.cornerRadius = (layer.cornerRadius == 0.0f) ? 30.0f : 0.0f;
    //设置透明度
    layer.opacity = (layer.opacity == 1.0f) ? 0.5f : 1.0f;
}

-(IBAction)removeAnimation:(id)sender
{
    [layer removeAnimationForKey:@"change"];
}

- (void)goBack
{
    [CATransaction begin];
    //显式事务默认开启动画效果,kCFBooleanTrue关闭
    [CATransaction setValue:(id)kCFBooleanFalse forKey:kCATransactionDisableActions];
    
    //动画执行时间
    [CATransaction setValue:[NSNumber numberWithFloat:0.5f] forKey:kCATransactionAnimationDuration];
    //[CATransaction setAnimationDuration:[NSNumber numberWithFloat:5.0f]];
//    layer.cornerRadius = (layer.cornerRadius == 0.0f) ? 30.0f : 0.0f;
    layer.opacity = (layer.opacity == 1.0f) ? 0.0f : 1.0f;
    if (layer.position.y == 200) {
        layer.bounds = CGRectMake(0, 0, 200, 200);
        layer.position = CGPointMake(160, 250);
    } else {
        layer.bounds = CGRectMake(0, 0, 200, 200);
        layer.position = CGPointMake(160, 200);
    }
    
    [CATransaction commit];
}

-(IBAction)oldClick:(id)sender
{
    [CATransaction begin];
    //显式事务默认开启动画效果,kCFBooleanTrue关闭
    [CATransaction setValue:(id)kCFBooleanFalse forKey:kCATransactionDisableActions];
    
    //动画执行时间
    [CATransaction setValue:[NSNumber numberWithFloat:0.6f] forKey:kCATransactionAnimationDuration];
    //[CATransaction setAnimationDuration:[NSNumber numberWithFloat:5.0f]];
//    layer.cornerRadius = (layer.cornerRadius == 0.0f) ? 30.0f : 0.0f;
    layer.opacity = (layer.opacity == 1.0f) ? 0.0f : 1.0f;
    if (layer.position.y == 200) {
        layer.bounds = CGRectMake(0, 0, 200, 200);
        layer.position = CGPointMake(160, 250);
    } else {
        layer.bounds = CGRectMake(0, 0, 200, 200);
        layer.position = CGPointMake(160, 200);
    }
    
    [CATransaction commit];
    
    [self performSelector:@selector(goBack) withObject:nil afterDelay:0.3];
    
    //color
//    //需要改变的属性
//    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];
//    [animation setDuration:5.0];
//    CGColorRef red = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0f].CGColor;
//    CGColorRef green = [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:1.0f].CGColor;
//    [animation setFromValue:(id)red];  
//    [animation setToValue:(id)green];
////    CFRelease(red);
////    CFRelease(green); 
//    //执行时间
//    animation.duration = 3.0;
//    //执行次数
//    animation.repeatCount = 1;
//    layer.backgroundColor = [UIColor blueColor].CGColor;
//    [layer addAnimation:animation forKey:@"change"];
    
//    //ddd
//    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"opacity"];
//    animation.fromValue=[NSNumber numberWithFloat:1.0];
//    animation.toValue=[NSNumber numberWithFloat:0.0];
//    animation.autoreverses=YES;
//    animation.duration = 0.1;
//    animation.repeatCount=FLT_MAX;
//    animation.removedOnCompletion=NO;
//    animation.fillMode=kCAFillModeForwards;
//    [layer addAnimation:animation forKey:@"change"];
    
//    //eee
//    CABasicAnimation* rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
//    //角度转弧度
//    rotationAnimation.toValue = [NSNumber numberWithFloat:3.0];
//    rotationAnimation.duration = 1.0f;
//    //回退动画
//    rotationAnimation.autoreverses = YES; 
//    //动画开始结束的快慢，设置为加速
//    rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
//    [layer addAnimation:rotationAnimation forKey:@"revItUpAnimation"];
    
//    ///fff
//    CATransition *animation = [CATransition animation];
//    [animation setDuration:1.25f];
//    [animation setTimingFunction:[CAMediaTimingFunction
//                                  functionWithName:kCAMediaTimingFunctionEaseIn]];
//    [animation setType:kCATransitionPush];
//    [animation setSubtype: kCATransitionFromBottom];
//    [layer addAnimation:animation forKey:@"Reveal"];
    
    //ooo
//    CATransition *animation = [CATransition animation];
//    [animation setDuration:0.35];
//    [animation setTimingFunction:UIViewAnimationCurveEaseInOut];
//    if (!curled){
//        //animation.type = @"mapCurl";
//        animation.type = @"oglFlip";
//        animation.fillMode = kCAFillModeForwards;
//        animation.endProgress = 0.99;
//    } else {
//        //animation.type = @"mapUnCurl";
//        animation.type = @"pageCurl";
//        animation.fillMode = kCAFillModeBackwards;
//        animation.startProgress = 0.01;
//    }
//    [animation setRemovedOnCompletion:NO];
//    [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
//    [layer addAnimation:animation forKey:@"pageCurlAnimation"];
//    // Disable user interaction where necessary
//    if (!curled) {
//        
//    } else {
//        
//    }
//    curled = !curled;
    
//    //pp
//    [UIView beginAnimations:@"Curl"context:nil];//动画开始
//    [UIView setAnimationDuration:0.75];
//    [UIView setAnimationDelegate:self];
//    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
//    [self.view removeFromSuperview];
//    [UIView commitAnimations];
    
//    CATransition *animation = [CATransition animation];
//    [animation setDuration:1.25f];
//    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
//    [animation setType:kCATransitionReveal];
//    [animation setSubtype:kCATransitionFromBottom];
//    [self.view.layer addAnimation:animation forKey:@"Reveal"];
}

-(IBAction)oldOldClick:(id)sender
{
    [CATransaction begin];
    [CATransaction begin];
    [CATransaction setDisableActions:YES];
    layer.cornerRadius = (layer.cornerRadius == 0.0f) ? 30.0f : 0.0f;
    [CATransaction commit];
    //上面的动画并不会立即执行，需要等最外层的commit
    [NSThread sleepForTimeInterval:3];
    //显式事务默认开启动画效果,kCFBooleanTrue关闭
    [CATransaction setValue:(id)kCFBooleanFalse
                     forKey:kCATransactionDisableActions];
    //动画执行时间
    //[CATransaction setValue:[NSNumber numberWithFloat:3.0f] forKey:kCATransactionAnimationDuration];
    [CATransaction setAnimationDuration:1];
    anotherLayer.cornerRadius = (anotherLayer.cornerRadius == 0.0f) ? 30.0f : 0.0f;
    
    
    [CATransaction commit];
}

- (void)viewDidUnload
{
    [self setTxtName:nil];
    [self setUibgimage:nil];
    [self setUibgimage1:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    self.detailDescriptionLabel = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = NSLocalizedString(@"Detail", @"Detail");
    }
    return self;
}
							
#pragma mark - Split view

- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
    barButtonItem.title = NSLocalizedString(@"Master1", @"Master1");
    [self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
    self.masterPopoverController = popoverController;
}

- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
    // Called when the view is shown again in the split view, invalidating the button and popover controller.
    [self.navigationItem setLeftBarButtonItem:nil animated:YES];
    self.masterPopoverController = nil;
}

-(IBAction)doAction:(id)sender
{
    NSString * str = [[NSString alloc] initWithFormat:@"hello: %@", self.txtName.text];
    
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"title" message:str delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
    [alert show];
    [alert release];
    [str release];
}

#pragma mark -
#pragma mark UIScrollViewDelegate

// 触摸屏幕来滚动画面还是其他的方法使得画面滚动，皆触发该函数
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    NSLog(@"Scrolling...");
}

// 触摸屏幕并拖拽画面，再松开，最后停止时，触发该函数
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    NSLog(@"scrollViewDidEndDragging  -  End of Scrolling.");
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    NSLog(@"begin");
}

// 滚动停止时，触发该函数

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    NSLog(@"scrollViewDidEndDecelerating  -   End of Scrolling.");
}

// 调用以下函数，来自动滚动到想要的位置，此过程中设置有动画效果，停止时，触发该函数

// UIScrollView的setContentOffset:animated: 

// UIScrollView的scrollRectToVisible:animated:

// UITableView的scrollToRowAtIndexPath:atScrollPosition:animated:

// UITableView的selectRowAtIndexPath:animated:scrollPosition:

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
    NSLog(@"scrollViewDidEndScrollingAnimation  -   End of Scrolling.");
}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
    NSLog(@"ddddd");
}

@end
